/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gruppe1projekt.ModelLayer;

import gruppe1projekt.GUILayer.prototypes.IncludeInColumn;
import java.util.ArrayList;
import java.util.Date;

public class Product
{
    private String Name;
    private String Description;
    private int PurchasePrice;
    private ArrayList<Product> SubProduct;
    private long Barcode;
    private int Count;
    private boolean IsUnique;
    private ArrayList<ProductItem> ProductItems;
    private ArrayList<Price> Prices;
    private int maxAmount;
    private int minAmount;
    private boolean IsDiscontinued;
    private Supplier Supplier;

    public Product()
    {
        this.SubProduct = new ArrayList<Product>();
        this.ProductItems = new ArrayList<ProductItem>();
        this.Prices = new ArrayList<Price>();
    }

    public Product(String Name, String Description, int PurchasePrice, ArrayList<Product> SubProduct, long Barcode, int Count, boolean IsUnique)
    {
        this.SubProduct = new ArrayList<Product>();
        this.ProductItems = new ArrayList<ProductItem>();
        this.Prices = new ArrayList<Price>();

        this.Name = Name;
        this.Description = Description;
        this.PurchasePrice = PurchasePrice;
        this.SubProduct = SubProduct;
        this.Barcode = Barcode;
        this.Count = Count;
        this.IsUnique = IsUnique;
    }

    public Supplier getSupplier()
    {
        return Supplier;
    }

    public void setSupplier(Supplier Supplier)
    {
        this.Supplier = Supplier;
    }

    @IncludeInColumn(ColumnName="Stregkode")
    public Long getBarcode()
    {
        return Barcode;
    }

    public boolean getIsUnique()
    {
        return IsUnique;
    }

    @IncludeInColumn(ColumnName="Antal")
    public Integer getCount()
    {
        if(this.IsUnique)
        {
            return ProductItems.size();
        }
        else
        {
            return this.Count;
        }
    }

    public String getDescription()
    {
        return Description;
    }

    @IncludeInColumn(ColumnName="Navn")
    public String getName()
    {
        return Name;
    }

    @IncludeInColumn(ColumnName="Købs pris")
    public Integer getPurchasePrice()
    {
        return PurchasePrice;
    }
    
    public ArrayList<Product> getSubProducts()
    {
        return SubProduct;
    }

    public ArrayList<ProductItem> getProductItems()
    {
        return ProductItems;
    }

    public ArrayList<Price> getPrices()
    {
        return Prices;
    }

    public void setBarcode(long Barcode)
    {
        this.Barcode = Barcode;
    }

    public void setCount(int Count)
    {
        this.Count = Count;
    }

    public void setDescription(String Description)
    {
        this.Description = Description;
    }

    public void setIsUnique(boolean IsUnique)
    {
        this.IsUnique = IsUnique;
    }

    public void setName(String Name)
    {
        this.Name = Name;
    }

    public void setPurchasePrice(int PurchasePrice)
    {
        this.PurchasePrice = PurchasePrice;
    }
    

    public void setSubProduct(ArrayList<Product> SubProduct)
    {
        this.SubProduct = SubProduct;
    }

    public void addSubProduct(Product product)
    {
        this.SubProduct.add(product);
    }

    //Tilføjer et serialnummer til produktet
    public void addProductItem(ProductItem PI)
    {
        this.ProductItems.add(PI);
    }
    //Tilføjer ny pris til produktet

    public void addPrice(Price P)
    {
        this.Prices.add(P);
    }

//Tilføj Eksempel
    public void addCount(int number)
    {
        this.setCount(this.getCount() + number);
    }

    @IncludeInColumn(ColumnName="Pris")
    public Price getCurrentPrice()
    {
        Date currentDate = new Date();

        for (int i = this.Prices.size()-1; i >= 0; i--)
        {
            Price P = Prices.get(i);
            if (P.IsDiscount() && P.getStartDate() != null && P.getEndDate() != null)
            {
                if (currentDate.after(P.getStartDate()) && currentDate.before(P.getEndDate()))
                {
                    return P;
                }
                else
                {
                    continue;
                }
            }
            else
            {
                return P;
            }
        }

        return null;
    }

    public int getMinAmount()
    {
        return minAmount;
    }

    public void setMinAmount(int minAmount)
    {
        this.minAmount = minAmount;
    }

    public int getMaxAmount()
    {
        return maxAmount;
    }

    public void setMaxAmount(int maxAmount)
    {
        this.maxAmount = maxAmount;
    }

    public boolean IsDiscontinued()
    {
        return IsDiscontinued;
    }

    public void setIsDiscontinued(boolean IsDiscontinued)
    {
        this.IsDiscontinued = IsDiscontinued;
    }

    @Override
    public String toString()
    {
        return getName();
    }
}



